#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <filesystem>
#include "yoloInterface.h"

YOLOV8 *m_yolo;                   /// yolo检测模型
std::string m_YOLOmodelPath; /// yolo模型权重文件
std::string m_YOLOClassName; /// yolo检测的分类文件

void yolo_init(std::string onnx_path, std::string classname_path)
{
    Config config;
    config.confThreshold = 0.2;
    config.nmsThreshold = 0.5;
    config.scoreThreshold = 0.5;
    config.inpWidth = 640;
    config.inpHeight = 480;
    config.onnx_path = onnx_path;

    m_yolo = new YOLOV8(config, m_YOLOClassName);
}

int main()
{
    // 1 获取当前项目路径
    std::string path = std::filesystem::current_path().parent_path().string();
    std::string image_path = path + "/images/color-0.21.png";
    std::cout << "current path is : " << image_path << std::endl;

    // 2 读取图片
    cv::Mat image = cv::imread(image_path, 1);

    // 3 yolo init
    m_YOLOmodelPath = path + "/config/best.onnx";
    m_YOLOClassName = path + "/config/classes.txt";
    yolo_init(m_YOLOmodelPath, m_YOLOClassName);

    // 4 detect
    std::vector<outputDetection> m_outDetections; /// YOLOV8 getDetection接口输出的检测结果
    m_yolo->detect(image); // 检测
    m_outDetections.clear();
    m_outDetections = m_yolo->getDetection(); // 获取检测到的ROI区域

    std::cout << "outDetections.size() = " << m_outDetections.size() << std::endl;
    for (int i = 0; i < m_outDetections.size(); i++)
    {
        std::cout << "识别到的对象 = " << m_outDetections[i].className << std::endl;
        std::cout << "识别到的对象的置信度 = " << m_outDetections[i].confidence << std::endl;
        std::cout << "识别到的对象的边框 = " << m_outDetections[i].box << std::endl;
    }

    // 3 显示图片
    cv::imshow("outDetections", image);
    cv::waitKey(0);

    return 0;
}
